                        $q = "SELECT order_number,payment_class,order_payment_trans_id FROM #__{vm}_payment_method,#__{vm}_order_payment,#__{vm}_orders WHERE ";
                        $q .= "#__{vm}_order_payment.order_id='".$db->getEscaped($d['order_id'])."' ";
                        $q .= "AND #__{vm}_orders.order_id='".$db->getEscaped($d['order_id'])."' ";
                        $q .= "AND #__{vm}_order_payment.payment_method_id=#__{vm}_payment_method.payment_method_id";
                        $db->query( $q );
                        $db->next_record();
                        $payment_class = $db->f("payment_class");

                        if ( $payment_class=="ps_quickpay" ) {
                            require_once( CLASSPATH."payment/ps_quickpay.php");
                            
                            $paymentObj = new ps_quickpay();
                    
                            /*
                             * When the order changes from Confirmed or Pending to
                             * Shipped, perform the delayed capture.
                             */
                            if( ($curr_order_status=="P" || $curr_order_status=="C") && $d["order_status"]=="S") {
                                if( !$paymentObj->capture_payment( $d )) {
                                    return false;
                                }
                            }
	
                            /*
                             * If an authorized order gets cancelled, void the authorization.
                             */
                            if( $curr_order_status=="C" && $d["order_status"]=="X" ) {
                                /* Accept errors here - we may need to clean up manually afterwards */
                                $paymentObj->void_authorization( $d );
                            }

                            /*
                             * If a sent and captured order gets refunded, return the payment.
                             */
                            if( $curr_order_status=="S" && $d["order_status"]=="R" ) {
                                /* Accept errors here - we may need to clean up manually afterwards */
                                $paymentObj->do_refund( $d );
                            }
                            
                            /*
                             *  Ignore the following state transitions w.r.t. QuickPay:
                             *  Pending -> Cancelled
                             *  Pending -> Refunded (not possible as no money was drawn)
                             */
                        }
